package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.common.constant.ClueStatusConstants;
import com.qk.doman.clue.ClueDO;
import com.qk.dto.clue.*;
import com.qk.entity.Clue;
import com.qk.management.anno.LogOperation;
import com.qk.management.service.ClueService;
import com.qk.vo.clue.ClueVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author 16778
 * @date 2025/10/13 16:56
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/clues")
public class ClueController {
    @Autowired
    private ClueService clueService;

    @LogOperation
    @PostMapping
    public Result addClue(@RequestBody ClueDTO dto){
        clueService.addClue(dto);
        return Result.success();
    }

    @GetMapping
    public Result page(ClueQueryDTO dto){
        PageResult<ClueDO> result = clueService.pageList(dto);
        return Result.success(result);
    }

    @LogOperation
    @PutMapping("/assign/{clueId}/{userId}")
    public Result updateByUserId(@PathVariable Integer clueId,@PathVariable Integer userId){
        Clue clue = Clue.builder()
                .id(clueId)
                .userId(userId)
                .updateTime(LocalDateTime.now())
                .status(ClueStatusConstants.WAIT_FOLLOW_UP)
                .build();
        clueService.updateById(clue);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result selectWithRecords(@PathVariable Integer id){
        ClueVO clueVO =clueService.selectWithRecords(id);
        return Result.success(clueVO);
    }

    @LogOperation
    @PutMapping
    public Result update(@RequestBody UpdateClueDTO dto){
        clueService.updateClueTrackRecord(dto);
        return Result.success();
    }

    @LogOperation
    @PutMapping("/false/{id}")
    public Result updateFalseClue(@PathVariable Integer id, @RequestBody MarkFalseClueDTO dto){
        clueService.updateFalseClue(id,dto);
        return Result.success();
    }

    @LogOperation
    @PutMapping("/toBusiness/{id}")
    public Result convertToBusiness(@PathVariable Integer id){
        clueService.convertTOBusiness(id);
        return Result.success();
    }

    @GetMapping("/pool")
    public Result pool(CluePoolDTO dto){
        return Result.success(clueService.pool(dto));
    }

}
